<script type="text/javascript" src="<?php echo $this->webroot;?>js/jquery.ui.core.js"></script>
<script type="text/javascript" src="<?php echo $this->webroot;?>js/jquery.ui.datepicker.js"></script>
<link rel="stylesheet" type="text/css" href="<?php echo $this->webroot?>css/jquery.ui.datepicker.css">
<link rel="stylesheet" type="text/css" href="<?php echo $this->webroot?>css/jquery-ui.css">
<script type="text/javascript">
	$(document).ready(function(){
		$('select[name=vitrixh]').change(function(){
			$(this).parent().submit();
		});
		$(".div_date").hide();
		$('#SELECT-type').change(function(){
			if($(this).val() == 'tieude' || $(this).val() == 'noidung' || $(this).val() == 'tenlienhe'){
				$(".div_date").hide();
				$("#INPUT-search").show();
			}else if($(this).val() == 'ngaydang'){
				$(".div_date").show();
				$("#INPUT-search").hide();
			}
		});
		$( ".datepicker" ).datepicker({
			changeMonth: true,
			changeYear: true,
			dateFormat: 'dd-mm-yy',
			dayNamesMin: ['CN', 'T2', 'T3', 'T4', 'T5', 'T6', 'T7'],
			monthNamesShort: ['Tháng 1','Tháng 2','Tháng 3','Tháng 4','Tháng 5','Tháng 6','Tháng 7','Tháng 8','Tháng 9','Tháng 10','Tháng 11','Tháng 12'],
			yearRange: (new Date().getFullYear()-10) + ':'+ (new Date().getFullYear())
		});
	});	
	function toggle(source) {
		checkboxes = document.getElementsByName('idraovat');
		for(var i in checkboxes)
			checkboxes[i].checked = source.checked;
	}
	function deletealltinrao(){
		var data = new Array();
		$("input[name='idraovat']:checked").each(function(i) {
				data.push($(this).val());
		});
		$.ajax({
			url:'<?php echo $this->webroot;?>tinraos/admin_delete_all/',
			data: {'idraovats[]': data},
			success: function(data){
				if(data.status == 'ok'){
					window.location.href = '<?php echo $this->webroot;?>tinraos/admin_index';
				}else{
					alert('Tin rao chưa được xóa');
				}
			},
			dataType: 'json',
			type: 'post'
		});
		return false;
	}
</script>
<div id="content">
	
	<!-- Box -->
	<div class="box">
		<!-- Box Head -->
		<div class="box-head">
			<h2 class="left">Tin rao</h2>
			<div class="right">
				<form method="post" action="admin_search">
				<label>Tìm kiếm tin rao:</label>
				<input type="text" name="inputsearch" id="INPUT-search" class="field small-field" />
				<div class="div_date">
					<label>Từ ngày</label>
					<input type="text" name="fromdate" class="field small-field datepicker" />
					<label>Đến ngày</label>
					<input type="text" name="todate" class="field small-field datepicker" />
				</div>
				<select id="SELECT-type" name="type">
					<option value="tenlienhe">Tên liên hệ</option>
					<option value="tieude">Tiêu đề</option>
					<option value="noidung">Nội dung</option>
					<option value="ngaydang">Ngày đăng</option>
				</select>
				<input type="submit" class="button" value="search" />
				</form>
			</div>
		</div>
		<!-- End Box Head -->	

		<!-- Table -->
		<div class="table">
			<table width="100%" border="0" cellspacing="0" cellpadding="0">
				<tr>
					<th width="13"><input onclick="toggle(this)" type="checkbox" name="selectall" id="Select-all"></th>
					<th><?php echo $this->Paginator->sort('Tiêu đề', 'tieude');?></th>
					<th><?php echo $this->Paginator->sort('Nội dung','noidung');?></th>
					<th><?php echo $this->Paginator->sort('Vị trí xuất hiện','vitrixh');?></th>
					<th><?php echo $this->Paginator->sort('Tên liên hệ','tenlienhe');?></th>
					<th><?php echo $this->Paginator->sort('Số điện thoại','sdtlienhe');?></th>
					<th><?php echo $this->Paginator->sort('Email','email');?></th>
					<th><?php echo $this->Paginator->sort('Thuộc dự án','Duan.tieude');?></th>
					<th><?php echo $this->Paginator->sort('Ngày đăng','ngaydang');?></th>
					<th width="110" class="ac">Điều khiển</th>
				</tr>
				<?php
				$i = 0;
				$dem = 0;
				foreach ($tinraos as $tinrao):
					$class = null;
					if ($i++ % 2 == 0) {
						$class = ' class="altrow"';
					}
					$dem ++;
				?>
				<tr>
					<td><input type="checkbox" name="idraovat" value="<?php echo $tinrao['Tinrao']['id']; ?>"></td>
					<td><h3><a href="#"><?php echo $tinrao['Tinrao']['tieude']; ?></a></h3></td>
					<td><?php echo $tinrao['Tinrao']['noidung']; ?></td>
					<td>
						<form name="changevitrixh" id="changevitrixh" method="post" action="<?php echo $this->webroot;?>tinraos/change_vitrixh">
							<input type="hidden" name="idtinrao" value="<?php echo $tinrao['Tinrao']['id'];?>" />
							<?php if($tinrao['Tinrao']['vitrixh']>10){
								echo "<b>Ngoài top 10</b>";
							}?>
							<select name="vitrixh">
								<?php
									for($i=1; $i<=10; $i++){
										if($i==$tinrao['Tinrao']['vitrixh']){
											echo '<option selected value="'.$i.'">'.$i.'</option>';
										}else{
											echo '<option value="'.$i.'">'.$i.'</option>';
										}
									}
								?>
								
							</select>
						</form>
					</td>
					<td><?php echo $tinrao['Tinrao']['tenlienhe']; ?></td>
					<td><?php echo $tinrao['Tinrao']['sdtlienhe']; ?></td>
					<td><?php echo $tinrao['Tinrao']['email']; ?></td>
					<td><?php echo $tinrao['Duan']['tieude']; ?></td>
					<td><?php echo $date = date('d-m-Y', strtotime($tinrao['Tinrao']['ngaydang']));?></td>
					<td><?php echo $this->Html->link(__('Delete', true), array('action' => 'admin_delete', $tinrao['Tinrao']['id']), null, sprintf(__('Bạn chắc chắn muốn xóa tin rao này?', true), $tinrao['Tinrao']['id'])); ?><?php echo $this->Html->link(__('Edit', true), array('action' => 'admin_edit', $tinrao['Tinrao']['id'])); ?></td>
				</tr>
				<?php endforeach; ?>
				<tr>
					<td><input type="submit" onclick="deletealltinrao()" value="Xóa lựa chọn" /></td>
				</tr>
			</table>
			
			
			<!-- Pagging -->
			<div class="paging">
				<?php echo $this->Paginator->prev('<< ' . __('previous', true), array(), null, array('class'=>'disabled'));?>
			 | 	<?php echo $this->Paginator->numbers();?>
		 |
				<?php echo $this->Paginator->next(__('next', true) . ' >>', array(), null, array('class' => 'disabled'));?>
			</div>
			<!--<div class="pagging">
				<div class="left">Showing 1-12 of 44</div>
				<div class="right">
					<a href="#">Previous</a>
					<a href="#">1</a>
					<a href="#">2</a>
					<a href="#">3</a>
					<a href="#">4</a>
					<a href="#">245</a>
					<span>...</span>
					<a href="#">Next</a>
					<a href="#">View all</a>
				</div>
			</div>-->
			<!-- End Pagging -->
			
		</div>
		<!-- Table -->
		
	</div>
	<!-- End Box -->
	
	<!-- Box -->
	
	<!-- End Box -->

</div>